package com.vonchenchen.usbmuxd_android.usbmuxd.localconn.socket;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

/**
 * Created by lidechen on 3/28/17.
 */

public class SocketDistributer extends SocketConnector {

    private Socket mSocket;

    private InputStream mSocketInput;
    private OutputStream mSocketOutput;

    public SocketDistributer(String address, int port) {
        super(address, port);
    }

    @Override
    public InputStream getInputStream() {
        return mSocketInput;
    }

    @Override
    public OutputStream getOutputStream() {
        return mSocketOutput;
    }

    @Override
    public void open() throws IOException {
        mSocket = new Socket("127.0.0.1", mPort);
        mSocket.setSendBufferSize(mSendBufferSize);
        if (mReceiveBufferSize > 0) {
            mSocket.setReceiveBufferSize(mReceiveBufferSize);
        }
        mSocketInput = mSocket.getInputStream();
        mSocketOutput = mSocket.getOutputStream();
    }

    @Override
    public void close() throws IOException {

        if (mSocket != null) {
            mSocket.close();
        }
    }
}
